<?php
/*
$ordinary = array('modifiers' => array());
$node = null;
$dir = opendir('old/ordinaries');
while ( ($subdir = readdir($dir)) != false ) {
  if ( $subdir{0} != '.' and is_dir('old/ordinaries/' . $subdir) ) {
    $ddir = opendir('old/ordinaries/' . $subdir );
    while ( ($file = readdir($ddir)) != false ) {
      if ( ($file{0} != '_') and substr($file,-4) == '.inc' ) {
        include_once 'old/ordinaries/' . $subdir . '/' . $file;
      }
    }
  }
}

  var_export ( $ordinary );
exit; */

/*
function rgb($arg) { return '0xFFFFFFF'; }
function get_mod($name) { return true; }
set_include_path('./old/');

$node = null;
$dir = opendir('old/ordinaries');
while ( ($subdir = readdir($dir)) != false ) {
  if ( $subdir{0} != '.' and is_dir('old/ordinaries/' . $subdir) ) {
    $ddir = opendir('old/ordinaries/' . $subdir );
    while ( ($file = readdir($ddir)) != false ) {
      if ( ($file{0} != '_') and substr($file,-4) == '.inc' ) {
        $name = substr($file,0,-4);
        $ordinary = array();
        include_once 'old/ordinaries/' . $subdir . '/' . $file;
        if ( array_key_exists('modifiers', $ordinary) ) {
          foreach ( $ordinary['modifiers'] as $modifier ) {
            switch ( $modifier[2] ) {
            case 'feature':
              echo "array ( '$modifier[1]', '$modifier[0]' ), // $name/feature\n";
              break;
            case 'ignore':
              echo "array ( '$modifier[1]', '$modifier[1]' ), // $name/modifier\n";
              break;
            case 'warn':

              echo "array ( '$modifier[1]', '$modifier[0]' ), // $name/modifier\n";

              break;
            case 'mod':
              echo "array ( '$modifier[1]', '$modifier[3]' ), // $name/modifier\n";

              break;
            }
          }
        }
      }
    }
  }
}

exit;
*/
/*
$ordinary_list = unserialize(file_get_contents('data/charge_list.dat'));
foreach ( $ordinary_list as $ord )
  echo "    array( '$ord[1]', '$ord[2]/$ord[0]' ), // $ord[3]\n";

exit;
*/

/*
include "tokeniser.inc";
//$blazon = 'azure a {big: fat bend} or';
$blazon = '';
for($i = 1; $i < count($argv); $i++) $blazon .= $argv[$i] . ' ';

$list = new tokeniser($blazon);
print_r($list->getTokens());
exit;

*/
/*
class languageDB {
  const CHARGE = 'charge';
}

class thing {
  protected $patterns;
 
  public function __construct() {
    include 'english/charge.inc';
  }
  
  public function analyse() {
    $charges = array();
    
    foreach ( $this->patterns[languageDB::CHARGE] as $pattern ) {
      list($group,$item) = explode('/',$pattern[1]);
      if ( !array_key_exists( $group, $charges ) ) $charges[$group] = array();
      $charges[$group][] = $item;
    }
    foreach($charges as $group => $items) {
      echo $group . "\n-----------\n";
      sort ( $items );

      $prev = '';

      foreach ( $items as $item ) {

        if ( $item != $prev ) echo "  $item\n";

        $prev = $item;

      }

      echo "-----------\n";
    }
  }
}

$x = new thing();
$x->analyse();
exit;
*/
include "parser.inc";



$p = new parser('english');


//echo $p->parse('azure');

//echo $p->parse("on a field of crusilly gules and azure a bend or");

//echo $p->parse("quarterly first and third azure second and 4th gules fretty or");

$blazon = '';

for($i = 1; $i < count($argv); $i++) $blazon .= $argv[$i] . ' ';

echo $p->parse($blazon);

?>
